<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>
	<title>Destroydrop &raquo; Javascripts &raquo; Tree</title>

	<link rel="StyleSheet" href="${base}/admin/dtree/dtree.css" type="text/css" />
	<script type="text/javascript" src="${base}/admin/js/jquery-1.7.min.js"></script>
	<script type="text/javascript" src="${base}/admin/dtree/dtree.js"></script>
	<script type="text/javascript" src="${base}/admin/contextmenu/jquery.contextmenu.js"></script>
	
	<style type="text/css">
		* {font-size:13px;}
		.contextMenu{display.none;}
	</style>

</head>

<body>
<div class="dtree">
	<form name="formCategory" id="category">
		<a href="javascript:ds.openAll();" >展开所有</a> | 
		<a href="javascript:ds.closeAll();" >关闭所有</a> |
		<input type="button" value="确定" onclick="ok()" /> | 
		<input type="button" value="取消" onclick="cancel()" />
		<br/><br/>
		
	<!--<textarea id="text" style=" width:400px; height:100px;"></textarea>-->
		
	<script type="text/javascript">

		ds = new dTree('ds');
		ds.add(0,-1,'<span sytle="font-size:30px;"><b>店铺分类列表</b></span>');
		
		<#list brandCategoryList as category>
			ds.add(${treeMap[category.id]},${(treeMap[category.parent.id])!'0'},'<input type="checkbox" name="radioCategory" id="${category.id}" value="${category.name}" />${(category.name)!''}','javascript:click(\'${category.id}\');','点击查看','category_main','dtree/img/folder.gif','dtree/img/folderopen.gif');
		</#list>
		document.write(ds);	
		
		function cancel(){
			parent.$.fancybox.close();
		}
		
		function click(id){
			document.getElementById(id).checked=!document.getElementById(id).checked;
		}
		
		function ok(){
			if(formCategory.radioCategory.length>1){
				var categoryNames="";
				var categoryIds="";
				for(var i=0;i<formCategory.radioCategory.length;i++){
					if(formCategory.radioCategory[i].checked){
						categoryNames=categoryNames+formCategory.radioCategory[i].value+",";
						categoryIds=categoryIds+formCategory.radioCategory[i].id+",";
					}
				}	
					categoryNames=categoryNames.substring(0,categoryNames.length-1);
					categoryIds=categoryIds.substring(0,categoryIds.length-1);
					parent.document.getElementById("categoryNames").value=categoryNames;
					parent.document.getElementById("categoryIds").value=categoryIds;
				if(categoryIds!=null&&categoryIds.length>0){
					$.post("brand_listGradeFields.action",{"categoryIds":categoryIds},function(data){
						data=eval("("+data+")");
						
	    				var parentGradeFieldsDiv=$(parent.document).find("#gradeFieldsDiv");
	    				
	    				var gradeFieldValue="";
	    				parentGradeFieldsDiv.empty();
	    				
	    				for(var i=0;i<data.length;i++){
	    					var span="<span><input type='checkbox' checked='checked'/>"+data[i]+"</span>";
	    					parentGradeFieldsDiv.append(span);
	    					gradeFieldValue+=data[i]+",";
	    				}
	    				gradeFieldValue=gradeFieldValue.substring(0,gradeFieldValue.lastIndexOf(","));
	    				parent.document.getElementById("gradeFieldStr").value=gradeFieldValue;;
		    			parent.$.fancybox.close();
						return;
					});
				}else{
					alert("未选择分类");
				}
			}else{
				 if(formCategory.radioCategory.checked){
					parent.document.getElementById("categoryNames").value=formCategory.radioCategory.value;
					parent.document.getElementById("categoryIds").value=formCategory.radioCategory.id;
					parent.$.fancybox.close();
					return;
				}else{
					alert("未选择分类");
				}
			}
		}
		//勾选
		window.onload=function(){
			var cid=parent.document.getElementById("categoryIds").value;
			var cidArr=cid.split(",");
			for(var i=0;i<cidArr.length;i++){
				document.getElementById(cidArr[i]).checked=true;
				ds.openTo($("#"+cidArr[i]).parent().prev().attr("id").substr(ds.obj.length+1));
			}
			//展开当前节点
		};
	</script>		
	</form>
</div>

</body>

</html>